﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Fuse8.ContentManagementFramework.Administration.Models;
using Fuse8.ContentManagementFramework.SystemFacade;

namespace Fuse8.ContentManagementFramework.Administration.Controllers
{
    public class CmsSiteMetaFieldsController : CmsBaseEntityMetaFieldLinkController
    {
        protected override string TypeParameter
        {
            get { return CmsConstants.SiteTypeParameter; }
        }

        [HttpGet]
        public ActionResult Values()
        {
            var site = CmsContext.ContextSite;
            return View(site.EntityMetaInformation);
        }

        [HttpPost]
        public ActionResult Values(IList<CmsEntityMetaModel> metas)
        {
            var site = CmsContext.ContextSite;
            if (ModelState.IsValid && metas != null)
            {
                foreach (var meta in metas)
                {
                    site.SetMetaValue(meta.Name, meta.Value, Type.GetType(meta.Type), true);
                }
                return RedirectToAction("values");
            }
            return View(site.EntityMetaInformation);
        }
    }
}